<?php
/**
 * User: Hunman
 * Date: 17.07.13
 * Time: 23:20
 */
class View_View
{
    public
    static $currency = " грн.";
    private
    static $templateUrl = "Template/";

    public $template;
    public $countPage;
    public $data = array();
    public $ordreNamePrice;
    public $limitBegin;
    public $limitCount;
    public $uriNoFilter;
	public $cartInfo;
	public $smallCart;

    public function view()
    {
        $name = $this->data["tovar"]["Name"];
        $description = $this->data["tovar"]['mini_data'] . $this->data["tovar"]['color'];

        if ($this->data != null)
            $this->data = array_merge(
                array(
                    'title'          => $name,
                    'countPage'      => $this->countPage,
                    'keywords'       => 'variables',
                    'description'    => $description,
                    'ordreNamePrice' => $this->ordreNamePrice,
                    'limitBegin'     => $this->limitBegin,
                    'limitCount'     => $this->limitCount,
                    'uriNoFilter'    => $this->uriNoFilter,
                    'tovar_in_cart'  => $this->cartInfo['count'],
                    'tovar_in_price' => $this->cartInfo['sum'],
                    'small_cart'     => $this->smallCart,
                ),
                $this->data
            );

        Twig_Autoloader::register();

        $loader = new Twig_Loader_Filesystem(self::$templateUrl);

        $temp = new Twig_Environment($loader);

        $template = $temp->loadTemplate($this->template);

        $template->display($this->data);

    }

    /**
     * Приготовление до вывода описания про состояние краткого описания корзины
     * @param array $cartInfo
     * @return string
     */
    public static
    function prepareSmallCartInfo( $cartInfo = array() )
    {
        switch ( (int) $cartInfo['count'] )
        {
            case 0:
                $smallCartInfoHtml = 'В корзине нет товаров';
                break ;
            case 1:
                $smallCartInfoHtml = 'В корзине 1 товар, цена ' . $cartInfo['sum'] . View_View::$currency;
                break ;
            case 2:
            case 3:
            case 4:
                $smallCartInfoHtml = "В корзине {$cartInfo['count']} товарa, цена " . $cartInfo['sum'] . View_View::$currency;
                break;
            default:
                $smallCartInfoHtml = "В корзине {$cartInfo['count']} товаров, цена " . $cartInfo['sum'] . View_View::$currency;
                break;
        }
        return $smallCartInfoHtml;
    }

}